package br.pucminas.inicial;

import java.util.List;
import java.util.Scanner;

import br.pucminas.dao.EditoraDAO;
import br.pucminas.models.Editora;

public class ConsultaEditorasComJPA {

	public static void main(String[] args) {
		
		EditoraDAO dao = new EditoraDAO();
		
		Editora novaEditora = new Editora();
		
		@SuppressWarnings("resource")
		Scanner entrada = new Scanner(System.in);
		
		System.out.println("Nome Editora: ");
		novaEditora.setNome(entrada.nextLine());
		
		System.out.println("Email editora: ");
		novaEditora.setEmail(entrada.nextLine());
		
		try {
			dao.inserirEditora(novaEditora);
		} catch (Exception e1) {
			e1.printStackTrace();
		}
		
		/*EntityManagerFactory factory = Persistence.createEntityManagerFactory("livrariaPU");
		
		EntityManager manager = factory.createEntityManager();
		
		Query query = manager.createQuery("SELECT e FROM Editora e");
		@SuppressWarnings("unchecked")
		List<Editora> editoras = query.getResultList();
		
		for(Editora e : editoras){
			System.out.println("EDITORA ["+e.getId()+"]: " + e.getNome() + " - " + e.getEmail());
		}

		manager.close();
		factory.close();*/
		
		
		List<Editora> editoras = dao.buscaEditoras();
		for(Editora e : editoras){
			System.out.println("EDITORA ["+e.getId()+"]: " + e.getNome() + " - " + e.getEmail());
		}
	}

}
